/*
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-04-24 11:26:19
 * @LastEditTime: 2021-04-24 23:15:16
 */
const babel = require('@babel/core')
const loaderUtils = require('loader-utils')

function loader(source) {
    // 获取 use.options值
    let options = loaderUtils.getOptions(this)
    let cb = this.async()
    babel.transform(source, {
        ...options,
        sourceMaps: true,
        filename: this.resourcePath.split(".").pop(),
    }, (err, result) => {
        cb(err, result.code, result.map)
    })
};

module.exports = loader;